package utils

import (
	"log"

	"github.com/dalixu/glog"
)

//ILogger 日志接口 所有的日志都使用这个接口来打印日志
type ILogger interface {
	Trace(v ...interface{})
	Tracef(format string, v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
}

//DefaultLogger 默认的logger实现 忽略任何日志
type DefaultLogger struct {
}

//Trace 打印Trace日志
func (eb *DefaultLogger) Trace(v ...interface{}) {
	log.Println(v...)
}

//Tracef 打印Trace日志
func (eb *DefaultLogger) Tracef(format string, v ...interface{}) {
	log.Printf(format, v...)
}

//Debug Debug
func (eb *DefaultLogger) Debug(v ...interface{}) {
	log.Println(v...)
}

//Debugf 打印Debugf日志
func (eb *DefaultLogger) Debugf(format string, v ...interface{}) {
	log.Printf(format, v...)
}

//Info 打印Info日志
func (eb *DefaultLogger) Info(v ...interface{}) {
	log.Println(v...)
}

//Infof 打印Infof日志
func (eb *DefaultLogger) Infof(format string, v ...interface{}) {
	log.Printf(format, v...)
}

//Warn 打印Warn日志
func (eb *DefaultLogger) Warn(v ...interface{}) {
	log.Println(v...)
}

//Warnf 打印Warnf日志
func (eb *DefaultLogger) Warnf(format string, v ...interface{}) {
	log.Printf(format, v...)
}

//Error 打印Error日志
func (eb *DefaultLogger) Error(v ...interface{}) {
	log.Println(v...)
}

//Errorf 打印Errorf日志
func (eb *DefaultLogger) Errorf(format string, v ...interface{}) {
	log.Printf(format, v...)
}

//Fatal 打印Fatal日志
func (eb *DefaultLogger) Fatal(v ...interface{}) {
	log.Println(v...)
}

//Fatalf 打印Fatalf日志
func (eb *DefaultLogger) Fatalf(format string, v ...interface{}) {
	log.Printf(format, v...)
}

var defaultLogger = &DefaultLogger{}

//使用GLOG库来实现日志记录
var manager glog.Manager

//Startup 使用glog来记录日志
func Startup(path string) {
	manager = glog.New(path)
}

//GetLogger 返回logger
func GetLogger(name string) ILogger {
	if manager != nil {
		return manager.GetLogger(name)
	}
	return defaultLogger
}
